<?php      
        require_once '/settings.php';
        /**
         * Klass som inkapslar mysqli objektet och håller reda på vår databasuppkoppling
         */
    class DBConnection {
        private $my_mysqli = NULL;
		
		public function Connect() {
	      $password = "";
	      $this->my_mysqli = new mysqli(DBSettings::DBHOST, 
	      								DBSettings::DBUSER, 
	      								DBSettings::DBPASSWORD,
	      								DBSettings::DATABASE);
		  
		  //Note charset should be set before any queries...
		  $this->my_mysqli->set_charset("utf8");
	      
	      // check connection
	      if ($this->my_mysqli->connect_errno) {
	          echo "Connect failed: $this->my_mysqli->connect_error";
	          return false;
	      }
	      return true;
	    }
		
		public function Close() {
	      $this->my_mysqli->close();
	    }
		
		
		/**
		 * @return mysqli_stmt
		 */
		public function Prepare($sql) {
			$stmt = $this->my_mysqli->prepare($sql);
			if ($stmt === FALSE) {
				echo "prepare of '$sql' failed " . $this->my_mysqli->error;
				return false;
			}
			return $stmt;
		}
	
}